package com.hxc.web.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import io.swagger.annotations.ApiOperation;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;

/**
 * Swagger2 配置
 * @author yzj
 */

@Configuration
@EnableSwagger2WebMvc
public class SwaggerConfig {

    @Bean(value = "defaultApi2")
    public Docket defaultApi2() {
        Docket docket = new Docket(DocumentationType.SWAGGER_2)
                // 接口文档的基本信息
                .apiInfo(new ApiInfoBuilder()
                        .title("火星村系统(API文档)")
                        .description("火星村系统(Swagger文档)")
                        .termsOfServiceUrl("/")
                        .version("1.0")
                        .build())
                //分组名称,不配置的话,默认值为:default
                .groupName("2.X版本")
                .select()
                //只有当方法上有@ApiOperation注解时，才能生成对应的接口文档
                .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
                //路径使用any风格（指定所有路径）
                .paths(PathSelectors.any())
                .build();
        return docket;
    }

}
